//
//  InstallUtil.swift
//  FrameProduct
//
//  Created by delegate on 2024/2/3.
//

import KeychainAccess

public struct InstallUtil {
    
    private static let uuidKey = "UUIDKey"
    private static let keychain = Keychain(service: GlobalConstants.appBundleIdentifier)
    
    public static var uuid: String {
        if let uuid = keychain[uuidKey], uuid.count > 0 {
            return uuid
        }
        let uuid = genUUIDString()
        keychain[uuidKey] = uuid
        return uuid
    }
    
    /// 生成UUID
   private static func genUUIDString() -> String {
        let uuidRef = CFUUIDCreate(kCFAllocatorDefault)
        let strRef = CFUUIDCreateString(kCFAllocatorDefault, uuidRef)!
        let uuidString = (strRef as String).replacingOccurrences(of: "-", with: "")
        return uuidString
    }
    
    public static var isInDebuggingMode: Bool {
        #if DEBUG
        return true
        #else
        return false
        #endif
    }

    public static var isInTestFlight: Bool {
        return Bundle.main.appStoreReceiptURL?.path.contains("sandboxReceipt") == true
    }

    public static var isNetworkActivityIndicatorVisible: Bool {
        get { return UIApplication.shared.isNetworkActivityIndicatorVisible }
        set { UIApplication.shared.isNetworkActivityIndicatorVisible = newValue }
    }

    public static var isPhone: Bool {
        return UIDevice.current.userInterfaceIdiom == .phone
    }

    public static var isRegisteredForRemoteNotifications: Bool {
        return UIApplication.shared.isRegisteredForRemoteNotifications
    }

    public static var isRunningOnSimulator: Bool {
        #if targetEnvironment(simulator)
        return true
        #else
        return false
        #endif
    }
}
